#include "../logs/log.h"

void test_log(const std::string &name)
{
    INFO("测试开始");
    LOG::Logger::ptr logger = LOG::loggerManager::getInstance().getLogger(name);
    logger->debug("测试日志");
    logger->info("测试日志");
    logger->warn("测试日志");
    logger->error("测试日志");
    logger->fatal("测试日志");
    int cnt = 0;
    while (cnt < 20000)
    {
        logger->error("文件创建失败%d", cnt++);
    }
    INFO("测试结束");
}
int main()
{
    // 使用日志器类进行异步日志输出
    // LOG::Formatter::ptr fmt = std::make_shared<LOG::Formatter>();
    LOG::Formatter::ptr fmt(new LOG::Formatter()); // 对象实例化
    // 通过建造者模式来搭建日志器
    std::unique_ptr<LOG::LoggerBuilder> builder(new LOG::GlobalLoggerBuilder());
    builder->buildLoggerLevel(LOG::LogLevel::value::INFO);
    builder->buildLoggerName("async_root");
    builder->buildLoggerFormat(fmt);
    builder->buildLoggerType(LOG::LoggerType::LOGGER_ASYNC);
    builder->buildSink<LOG::StdoutSink>();
    builder->buildSink<LOG::FileSink>("./log_test/async.log");
    builder->buildSink<LOG::RollSink>("./log_roll/log-", 1024 * 1024);
    builder->build();
    test_log("async_root");

    return 0;
}
